package com.sinaapp.mrblog.game.Assasin.model;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Circle;
import com.sinaapp.mrblog.game.Assasin.stage.GameStage;
import com.sinaapp.mrblog.game.Assasin.util.AssasinConst;
import com.sinaapp.mrblog.game.Assasin.util.AssasinManager;
import com.sinaapp.mrblog.game.Assasin.util.Director;


public class Hole extends BaseActor{

	public static final int HOLE_STATE_HIDE = 0;
	public static final int HOLE_STATE_ENABLE = 1;
	public static final int HOLE_STATE_LOCK = 2;
	public static final int HOLE_STATE_PASSING = 3;
	public static final int HOLE_STATE_PASSED = 4;
	
	public static final float HOLE_WIDTH = 1f;
	public static final float HOLE_HEIGHT = 1f;
	public TextureRegion endRegion;
	public Sprite spriteEnd; 
	public ACircle cir;
	
	public Hole(float positionX, float positionY) {
		super(positionX, positionY, HOLE_WIDTH, HOLE_HEIGHT);
		setState(HOLE_STATE_HIDE);
		spriteEnd = new Sprite();
	}

	@Override
	public void act(float delta) {
		if(getState() == HOLE_STATE_HIDE){
			region = null;
		}else if(getState() == HOLE_STATE_LOCK){
			region = AssasinManager.holeLockRegion;
		}else if(getState() == HOLE_STATE_ENABLE){	
			region = AssasinManager.hole_AN.getKeyFrame(getStateTime(), true);
			if(bounds.overlaps(GameStage.killer.bounds) &&getState()==HOLE_STATE_ENABLE){
				setState(HOLE_STATE_PASSING);
				ACircle cir = new ACircle(this, 1, 1, 20, ACircle.STATE_WHITE, 1);
			    GameStage.getStage().addActor(cir);
			    GameStage.circles.add(cir);
			    GameStage.getStage().state=GameStage.STAGE_PAUSE;
			}
		}else if(getState() == HOLE_STATE_PASSING){	
			if(getStateTime()>2.0f){
				setState(HOLE_STATE_PASSED);
			}
		}else if(getState() == HOLE_STATE_PASSED){
			GameStage.getStage().setState(GameStage.STAGE_NEXT_LEVEL);
			setState(HOLE_STATE_HIDE);
		}
		
		endRegion = AssasinManager.greenScreenRegion;
		spriteEnd.setRegion(endRegion);
		spriteEnd.setBounds(getCenterX()-AssasinConst.GAMESTAGE_WIDTH,
				getCenterY()-AssasinConst.GAMESTAGE_HEIGHT, 
				AssasinConst.GAMESTAGE_WIDTH*2, 
				AssasinConst.GAMESTAGE_HEIGHT*2);
		
		
		super.act(delta);
	}

	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		if(getState() == HOLE_STATE_PASSING&&endRegion!=null){
			spriteEnd.draw(batch,0.5f);
		}
		super.draw(batch, parentAlpha);
	}

	@Override
	public void refreshStatus() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public TextureRegion getReadyRegion() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	
}
